//
//  ScrollDemo.swift
//  firstFontAttrDemo
//
//  Created by liy on 2025/1/22.
//

import SwiftUI

struct ScrollDemo: View {
  var body: some View {
    VStack {
      ScrollView(.vertical, content: {
        ForEach(0 ..< 130) { index in
          HStack {
            Circle()
              .fill(.red)
              .frame(width: 20, height: 20)

            Text("line\(index)")
          }
        }

      })
      .defaultScrollAnchor(.top) // 默认滚动到顶部
      .scrollIndicators(.visible) // 指示器
      .scrollDismissesKeyboard(.immediately)
      .scrollContentBackground(.visible)
      .frame(width: 300, height: 300)
      .background(.teal)
			
      //
      ScrollView(.horizontal) {
        HStack {
          ForEach(1 ..< 30) { _ in
            Rectangle()
							.fill(Color(red: 0.0, green: 0.0, blue: 0.5))
              .frame(width: 70, height: 70)
          }
        }
      }
      .frame(width: 300, height: 300)
      .background(.teal)
			.scrollIndicators(.hidden)
    }
  }
}

#Preview {
  ScrollDemo()
}
